home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / uupc11ys.zip / LIB / GETSEQ.C < prev    next >
C/C++ Source or Header  |  1993-04-10  |  4KB  |  115 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    g e t s e q . c                                                 */
  3. /*                                                                    */
  4. /*    Job sequence number routines for UUPC/extended                  */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*                          RCS Information                           */
  9. /*--------------------------------------------------------------------*/
  10.  
  11. /*
  12.  *    $Id: GETSEQ.C 1.3 1993/04/11 00:32:05 ahd Exp $
  13.  *
  14.  *    Revision history:
  15.  *    $Log: GETSEQ.C $
  16.  *     Revision 1.3  1993/04/11  00:32:05  ahd
  17.  *     Global edits for year, TEXT, etc.
  18.  *
  19.  * Revision 1.2  1992/11/19  02:58:00  ahd
  20.  * drop rcsid
  21.  *
  22.  * Revision 1.1  1992/11/16  05:00:26  ahd
  23.  * Initial revision
  24.  *
  25.  */
  26.  
  27.  
  28. /*--------------------------------------------------------------------*/
  29. /*                        System include files                        */
  30. /*--------------------------------------------------------------------*/
  31.  
  32. #include <stdio.h>
  33.  
  34.  
  35. /*--------------------------------------------------------------------*/
  36. /*                    UUPC/extended include files                     */
  37. /*--------------------------------------------------------------------*/
  38.  
  39. #include "lib.h"
  40. #include "hlib.h"
  41. #include "getseq.h"
  42.  
  43. currentfile();
  44.  
  45. /*--------------------------------------------------------------------*/
  46. /*    g e t s e q                                                     */
  47. /*                                                                    */
  48. /*    Return next available sequence number for UUPC processing       */
  49. /*--------------------------------------------------------------------*/
  50.  
  51. long getseq()
  52. {
  53.    char seqfile[FILENAME_MAX];
  54.    FILE *seqfile_fp;
  55.    long seq;
  56.  
  57.    mkfilename(seqfile, E_confdir, SFILENAME);
  58.    printmsg(4, "getseq: opening %s", seqfile);
  59.    if ((seqfile_fp = FOPEN(seqfile, "r",TEXT_MODE)) != nil(FILE)) {
  60.       fscanf(seqfile_fp, "%ld", &seq);
  61.       fclose(seqfile_fp);
  62.    } else {
  63.       printmsg(0, "getseq: can't find %s, creating", seqfile);
  64.       seq = 1;
  65.    };
  66.  
  67. /*--------------------------------------------------------------------*/
  68. /*                       Update sequence number                       */
  69. /*--------------------------------------------------------------------*/
  70.  
  71.    printmsg(5, "getseq: seq#=%ld", seq);
  72.  
  73.    if ((seqfile_fp = FOPEN(seqfile, "w",TEXT_MODE)) != nil(FILE))
  74.    {
  75.       fprintf(seqfile_fp, "%ld\n", seq+1);
  76.       fclose(seqfile_fp);
  77.    }
  78.    else {
  79.       printerr( seqfile );
  80.       panic();
  81.    }
  82.  
  83.    return seq;
  84.  
  85. } /*getseq*/
  86.  
  87. /*--------------------------------------------------------------------*/
  88. /*    J o b N u m b e r                                               */
  89. /*                                                                    */
  90. /*    Given a job sequence number, returns a character string for use */
  91. /*    in file names                                                   */
  92. /*--------------------------------------------------------------------*/
  93.  
  94. char *JobNumber( long sequence )
  95. {
  96.       static char buf[4];
  97.       const long base = bflag[F_ONECASE] ? 36 : 62;
  98.       static const char set[] =
  99.          "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  100.       size_t count = sizeof buf - 1;
  101.  
  102.       buf[count] = '\0';
  103.  
  104.       sequence %= (base*base*base);
  105.  
  106.       while( count-- > 0 )
  107.       {
  108.          buf[count] = set[ (int) (sequence % base) ];
  109.          sequence /= base ;
  110.       } /* while */
  111.  
  112.       return buf;
  113.  
  114. } /* JobNumber */
  115.